<template>
    <view class="pub_page pub_page_bg pub_mine_index pub_header_padding pub_tabbar_padding">
        <pub-head :headerConfig="headerConfig" @headerBack="headerBack"></pub-head>
        <pub-tabbar :active="3"></pub-tabbar>
        <div class="pub_page_scroll page_box" v-if="userInfo!=''">
            <div class="user_div" @click="$comFun.openWin('/pages/mine/info')">
                <pub-image class="headimg" :src="userInfo.avatar" :mode="'aspectFill'"></pub-image>
                <div class="info">
                    <div class="text">
                        <div class="name">{{ userInfo.nickName }}</div>
                        <!-- 性别 -->
                        <!-- <div class="sex"></div> -->
                        <span class="incode">邀请码：{{ userInfo.invitationCode }}</span>
                        <span class="copy" @click.stop="$comFun.toCopy(userInfo.invitationCode)"></span>
                    </div>
                    <div class="id">
                        <!-- 等级 -->
                        <div class="level" v-if="teamType === 2">团长</div>
                        <div class="mobile">{{ $comFun.replaceMobile(userInfo.mobile) }}</div>
                    </div>
                    <text class="scan_icon icon-font-basic icon-b-scan" @click.stop="openScan"></text>
                </div>
            </div>
            <div class="nums_div">
                <div class="num_1" v-if="numShow">
                    <div class="li" @click="jumpPage({url:'/pages/mine/log',data:{openType:1}})">
                        <div class="txt">消费积分：</div>
                        <div class="num">{{ userInfo.integral || 0 }}</div>
                    </div>
                    <div class="li" @click="jumpPage({url:'/pages/mine/log',data:{openType:2}})">
                        <div class="txt">贡&nbsp;&nbsp;献&nbsp;值：</div>
                        <div class="num">{{ userInfo.contribution || 0 }}</div>
                    </div>
                </div>
                <div class="num_1" v-if="numShow">
                    <div class="li">
                        <div class="txt">本期待奖：</div>
                        <div class="num">{{ userInfo.prepareIntegral || 0 }}</div>
                    </div>
                    <div class="li">
                        <div class="txt">今日补贴：</div>
                        <div class="num">{{ userData.dayReward || 0 }}</div>
                    </div>
                </div>
                <div class="line" v-if="numShow"></div>
                <div class="num_2">
                    <div class="txt">当前抵用券
                        <text class="icon icon-font-basic" :class="[balanceShow?'icon-b-eye-2':'icon-b-eye-3']"
                            @click="balanceShow=!balanceShow"></text>
                    </div>
                    <div class="num" @click="jumpPage({url:'/pages/mine/log',data:{openType:3}})">
                        {{ balanceShow?userInfo.balance:'--' }}
                    </div>
                    <div class="btns">
                        <!-- <div class="btn" @click="jumpPage({url:'/pages/mine/recharge'})">充值</div>
                        <div class="btn btn_1" @click="jumpPage({url:'/pages/mine/withdrawal'})">提现</div> -->
                    </div>
                </div>
            </div>
            <!-- <div class="reward_div" v-if="userData != ''">
                <div class="total">
                    <div class="txt">参与银龄生态奖励
                        <text class="icon icon-font-basic" :class="[userDataShow?'icon-b-eye-2':'icon-b-eye-3']"
                            @click="userDataShow = !userDataShow"></text>
                    </div>
                    <div class="num">{{ userDataShow?userData.joinSilverAgeReward || 0:'--' }} <span class="yuan">元</span>
                    </div>
                </div>
                <div class="lis" v-if="userDataShow">
                    <div class="title">明细</div>
                    <div class="li">
                        <div class="txt">参与社区建设奖励金：</div>
                        <div class="num">{{ userData.joinCommunityReward || 0 }}</div>
                    </div>
                    <div class="li">
                        <div class="txt">社区管理奖励金：</div>
                        <div class="num">{{ userData.communityManageReward || 0 }}</div>
                    </div>
                    <div class="li">
                        <div class="txt">亲情贡献奖励金：</div>
                        <div class="num">{{ userData.kinshipReward || 0 }}</div>
                    </div>
                    <div class="li">
                        <div class="txt">区域代理奖励金：</div>
                        <div class="num">{{ userData.regionalAgentReward || 0 }}</div>
                    </div>
                </div>
            </div> -->
            <signIn @refresh="getUserInfo({needLoading: false})" />
            <div class="order_div">
                <div class="tabs">
                    <div class="tab" :class="orderType==2?'tab_active':''" @click="orderTypeClick(2)">物流发货</div>
                    <div class="tab" :class="orderType==1?'tab_active':''" @click="orderTypeClick(1)">上门提货</div>
                    <div class="more" @click="jumpPage({url:'/pages/order/ping_official_order',data:{openType:0}})">全部
                        <text class="icon icon-font-basic icon-b-arrow-1-2"></text>
                    </div>
                </div>
                <div class="lis" v-if="orderType==1">
                    <div class="li" @click="jumpPage({url:'/pages/mine/ping_self_order',data:{openType:1}})">
                        <pub-image class="img" :src="'../../static/bimg/img_11.png'"></pub-image>
                        <div class="txt">未核销</div>
                    </div>
                    <div class="li" @click="jumpPage({url:'/pages/mine/ping_self_order',data:{openType:2}})">
                        <pub-image class="img" :src="'../../static/bimg/img_12.png'"></pub-image>
                        <div class="txt">已核销</div>
                    </div>
                </div>
                <div class="lis" v-if="orderType==2">
                    <div class="li" @click="jumpPage({url:'/pages/order/ping_official_order',data:{openType:1}})">
                        <pub-image class="img" :src="'../../static/aimg/img_11.png'"></pub-image>
                        <div class="txt">待发货</div>
                    </div>
                    <div class="li" @click="jumpPage({url:'/pages/order/ping_official_order',data:{openType:2}})">
                        <pub-image class="img" :src="'../../static/aimg/img_12.png'"></pub-image>
                        <div class="txt">已发货</div>
                    </div>
                    <div class="li" @click="jumpPage({url:'/pages/order/ping_official_order',data:{openType:3}})">
                        <pub-image class="img" :src="'../../static/aimg/img_13.png'"></pub-image>
                        <div class="txt">已完成</div>
                    </div>
                </div>
            </div>
            <div class="tools_div">
                <div class="lis">
                    <div class="li" v-for="(li,key) in toolsList" :key="key"
                        @click="jumpPage({url:li.url,data:li.data || {},info:li})">
                        <pub-image class="img" :src="li.img"></pub-image>
                        <div class="txt">{{ li.txt }}</div>
                        <text class="icon icon-font-basic icon-b-arrow-1-2"></text>
                    </div>
                </div>
            </div>
            <br>
        </div>
    </view>
</template>

<script>
import signIn from '@/components/signIn/index.vue';
export default {
    components: { signIn },
    data() {
        return {
            headerConfig: {
                title: '个人中心',//标题栏内容
                header_color: '',

                right_type: 2,//右侧区域类型  0不出现  1文字  2图片
                right_content: '../../static/aimg/img_10.png',//右侧内容  right_type为1时文字内容 为2时图片链接
                right_color: '#fff',//右侧文字颜色
            },
            userInfo: '',
            userData: '',//用户金额数据
            teamType: -1,//0：不是团长 1：申请中 2：团长 3：已驳回

            mqModule: '',

            orderType: 2, //订单类型 1:上门提货  2:物流发货
            balanceShow: false,
            userDataShow: false,

            isAgent: false,
        };
    },
    computed: {
        toolsList() {
            const toolsList = [
                {
                    img: '../../static/bimg/img_13.png',
                    txt: '团长管理',
                    url: '/pages/mine/tuanz_manage',
                    needRealname: true,
                    show: this.teamType === 2
                }, {
                    img: '../../static/bimg/img_13.png',
                    txt: '团长申请',
                    url: '/pages/mine/tuanz',
                    needRealname: true,
                    show: this.teamType !== 2
                }, {
                    img: '../../static/bimg/img_14.png',
                    txt: '店铺入驻',
                    url: '/pages/store/join',
                    show: true
                }, {
                    img: '../../static/bimg/img_16.png',
                    txt: '亲情号绑定',
                    url: '/pages/mine/bind',
                    needRealname: true,
                    show: true
                }, {
                    img: '../../static/bimg/img_16.png',
                    txt: '实名认证',
                    url: '/pages/mine/realname',
                    show: true
                },
                {
                    img: '../../static/bimg/img_17.png',
                    txt: '代理门店',
                    url: '/pages/agentStore/index',
                    show: this.isAgent
                },
                {
                    img: '../../static/bimg/img_18.png',
                    txt: '我的地址',
                    url: '/pages/other/address',
                    show: true
                }, {
                    img: '../../static/bimg/img_19.png',
                    txt: '平台公告',
                    url: '/pages/other/notice',
                    show: true
                }, {
                    img: '../../static/bimg/img_19.png',
                    txt: '邀请好友',
                    url: '/pages/mine/invite',
                    show: true,
                    data: {
                        invitationCode: this.userInfo?.invitationCode
                    }
                }]
            return toolsList.filter(li => li.show)
        },
        numShow() {
            return true
            // return this.userInfo?.age >= 50
        }
    },
    onLoad() {
        // #ifdef APP-PLUS
        // this.mqModule = uni.requireNativePlugin("MeiQia-ChatPlugin");
        // #endif
    },
    onShow() {
        this.getUserInfo({
            needLoading: this.userInfo ? false : true,
        });
        this.getUserData()
        this.getTeamLeaderInfo()
    },
    methods: {
        headerBack(data) {
            if (data.type == 'right') {
                this.$comFun.openWin('/pages/other/set');
            }
        },
        openMeiQia() {
            this.mqModule.initChatViewManger();
            this.mqModule.setLoginCustomizedId(this.userInfo.mobile);
            this.mqModule.configChatViewStyle({
                "navBarBackgroundColor": "#1661F6", // 设置导航栏的背景色；
                "navBarTitleTxtColor": "#ffffff", // 设置导航栏上的 title 的颜色；
                "enableShowClientAvatar": true, // 是否支持当前用户头像的显示
            });
            this.mqModule.showMeiQiaChatView();
        },
        orderTypeClick(type) {
            this.$comFun.toast('敬请期待')
            // this.orderType = type;
        },
        async getUserData() {
            const res = await this.$request.get('user/getPersonData');
            // console.log(res);
            if (res.code == 200) {
                this.userData = res.result;
            }
            const res_1 = await this.$request.get('user/isAgent');
            if (res_1.code == 200) {
                this.isAgent = res_1.result;
            }
        },
        async getTeamLeaderInfo() {
            const res = await this.$request.get('user/getTeamLeaderInfo');
            if (res.code == 200) {
                this.teamType = res.result?.status || 0;
            }
        },
        openScan() {
            const that = this;
            uni.scanCode({
                success: function (res) {
                    // console.log('条码类型：' + res.scanType);
                    // console.log('条码内容：' + res.result);
                    // that.$comFun.toast(res.result)
                    let code = res?.result?.split('_') || [];
                    if (code?.length === 2) {
                        switch (code[0]) {
                            case 'AGENT':
                                that.jumpPage({ url: '/pages/agentStore/send', data: { mobile: code[1], giveType: 2 } })
                                break;
                            default:
                                break;
                        }
                    }
                }
            });
        }
    },
};
</script>

<style lang="scss" scoped>
@import "@/common/css/mine.scss";
</style>
